package com.xbongbong.paas.service.dynamic.crm.config;

import com.xbongbong.paas.service.dynamic.crm.strategy.CommunicateDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.CompetitorDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.CustomerDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.DecisionTreeDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.MainBusinessDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.PayDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.PaymentSheetDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.PushNotifyDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.SmsDynamicStrategy;
import com.xbongbong.paas.service.dynamic.crm.strategy.TeamDynamicStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 *动态策略配置
 *
 *@author weijianxun
 */
@Configuration
public class DynamicStrategyConfig {


    @Autowired
    private Map<String, CustomerDynamicStrategy> customerDynamicStrategyMap;
    @Autowired
    private Map<String, TeamDynamicStrategy> teamDynamicStrategyMap;
    @Autowired
    private Map<String, CommunicateDynamicStrategy> communicateDynamicStrategyMap;
    @Autowired
    private Map<String, SmsDynamicStrategy> smsDynamicStrategyMap;
    @Autowired
    private Map<String, PushNotifyDynamicStrategy> pushNotifyDynamicStrategyMap;
    @Autowired
    private Map<String, PaymentSheetDynamicStrategy> paymentSheetDynamicStrategyMap;
    @Autowired
    private Map<String, DecisionTreeDynamicStrategy> decisionTreeDynamicStrategyMap;
    @Autowired
    private Map<String, PayDynamicStrategy> payDynamicStrategyMap;
    @Autowired
    private Map<String, MainBusinessDynamicStrategy> mainBusinessDynamicStrategyMap;
    @Autowired
    private Map<String, CompetitorDynamicStrategy> competitorDynamicStrategyMap;


    @Bean("typeToMainBusinessDynamicStrategyMap")
    public Map<Integer, MainBusinessDynamicStrategy> typeToMainBusinessDynamicStrategyMap() {
        Map<Integer, MainBusinessDynamicStrategy> map = new HashMap<>(mainBusinessDynamicStrategyMap.size());
        mainBusinessDynamicStrategyMap.forEach((beanName, mainBusinessDynamicStrategy) -> {
            for (Integer businessType : mainBusinessDynamicStrategy.type()) {
                map.put(businessType, mainBusinessDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("typeToPayDynamicStrategyMap")
    public Map<Integer, PayDynamicStrategy> typeToPayDynamicStrategyMap() {
        Map<Integer, PayDynamicStrategy> map = new HashMap<>(payDynamicStrategyMap.size());
        payDynamicStrategyMap.forEach((beanName, payDynamicStrategy) -> {
            for (Integer businessType : payDynamicStrategy.type()) {
                map.put(businessType, payDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("typeToPaymentSheetDynamicStrategyMap")
    public Map<Integer,PaymentSheetDynamicStrategy> typeToPaymentSheetDynamicStrategyMap(){
        Map<Integer, PaymentSheetDynamicStrategy> map = new HashMap<>(paymentSheetDynamicStrategyMap.size());
        paymentSheetDynamicStrategyMap.forEach((beanName, paymentSheetDynamicStrategy) -> {
            for (Integer businessType : paymentSheetDynamicStrategy.type()) {
                map.put(businessType, paymentSheetDynamicStrategy);
            }
        });
        return map;
    }



    @Bean("typeToCustomerDynamicStrategyMap")
    public Map<Integer, CustomerDynamicStrategy> typeToCustomerDynamicStrategyMap() {
        Map<Integer, CustomerDynamicStrategy> map = new HashMap<>(customerDynamicStrategyMap.size());
        customerDynamicStrategyMap.forEach((beanName, customerDynamicStrategy) -> {
            for (Integer businessType : customerDynamicStrategy.type()) {
                map.put(businessType, customerDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("typeToTeamDynamicStrategyMap")
    public Map<Integer, TeamDynamicStrategy> typeToTeamDynamicStrategyMap() {
        Map<Integer, TeamDynamicStrategy> map = new HashMap<>(teamDynamicStrategyMap.size());
        teamDynamicStrategyMap.forEach((beanName, teamDynamicStrategy) -> {
            for (Integer businessType : teamDynamicStrategy.type()) {
                map.put(businessType, teamDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("typeToCommunicateDynamicStrategyMap")
    public Map<Integer, CommunicateDynamicStrategy> typeToCommunicateDynamicStrategyMap() {
        Map<Integer, CommunicateDynamicStrategy> map = new HashMap<>(communicateDynamicStrategyMap.size());
        communicateDynamicStrategyMap.forEach((beanName, communicateDynamicStrategy) -> {
            for (Integer businessType : communicateDynamicStrategy.type()) {
                map.put(businessType, communicateDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("typeToSmsDynamicStrategyMap")
    public Map<Integer,SmsDynamicStrategy> typeToSmsDynamicStrategyMap(){
        Map<Integer, SmsDynamicStrategy> map = new HashMap<>(smsDynamicStrategyMap.size());
        smsDynamicStrategyMap.forEach((beanName, smsDynamicStrategy) -> {
            for (Integer businessType : smsDynamicStrategy.type()) {
                map.put(businessType, smsDynamicStrategy);
            }
        });
        return map;
    }

    @Bean("pushNotifyDynamicStrategyMap")
    public Map<Integer,PushNotifyDynamicStrategy> typeToPushNotifyDynamicStrategyMap(){
        Map<Integer, PushNotifyDynamicStrategy> map = new HashMap<>(pushNotifyDynamicStrategyMap.size());
        pushNotifyDynamicStrategyMap.forEach((beanName, pushNotifyDynamicStrategy) -> {
            for (Integer businessType : pushNotifyDynamicStrategy.type()) {
                map.put(businessType, pushNotifyDynamicStrategy);
            }
        });
        return map;
    }
    @Bean("decisionTreeDynamicStrategyMap")
    public Map<Integer,DecisionTreeDynamicStrategy> typeToDecisionTreeDynamicStrategyMap(){
        Map<Integer, DecisionTreeDynamicStrategy> map = new HashMap<>(decisionTreeDynamicStrategyMap.size());
        decisionTreeDynamicStrategyMap.forEach((beanName, temp) -> {
            for (Integer businessType : temp.type()) {
                map.put(businessType, temp);
            }
        });
        return map;
    }


    @Bean("typeToCompetitorDynamicStrategyMap")
    public Map<Integer, CompetitorDynamicStrategy> typeToCompetitorDynamicStrategyMap() {
        Map<Integer, CompetitorDynamicStrategy> map = new HashMap<>(competitorDynamicStrategyMap.size());
        competitorDynamicStrategyMap.forEach((beanName, competitorDynamicStrategy) -> {
            for (Integer businessType : competitorDynamicStrategy.type()) {
                map.put(businessType, competitorDynamicStrategy);
            }
        });
        return map;
    }
}
